<template>
  <div>
    <div class="public-common">
        <div class="public-title" style="text-indent: 20px;;">文件阅办单列表</div>
        <div class="inline-btn">
          <label>来文单位：</label>
          <el-input v-model="searchdata.txtFromOrg"></el-input>
          <label>事由：</label>
          <el-input v-model="searchdata.txtReason"></el-input>
          <label>来文字号：</label>
          <el-input v-model="searchdata.txtFileWordNo"></el-input>
        </div>
        <div class="inline-btn">
          <label>标题：</label>
          <el-input v-model="searchdata.txtSubject"></el-input>
          <el-button type="primary" @click="searchBtn">搜索</el-button>
          <el-button type="primary" @click="aduitBtn" v-if="commonType == 1">审核</el-button>
          <el-button type="primary" @click="aduitBtn" v-if="commonType == 2">发布</el-button>
          <el-button type="primary" @click="aduitBtn" v-if="commonType == 3">查看</el-button>
        </div>
        <div class="" style="margin:2%;">
          <el-table :data="tableData" border width="100%" @selection-change="handleSelectionChange">
            <el-table-column type="index" width="50" label=" " fixed="left"></el-table-column>
            <el-table-column type="selection"  width="55"></el-table-column>
            <el-table-column prop="FromOrg"  label="来文单位" sortable></el-table-column>
            <el-table-column prop="FromDate"  label="来文日期" sortable></el-table-column>
            <el-table-column prop="Reason"  label="事由" sortable></el-table-column>
            <el-table-column prop="FileWordNo"  label="来文字号" sortable></el-table-column>
            <el-table-column prop="Subject"  label="标题" sortable></el-table-column>
            <el-table-column prop="ExpiryHours"  label="时效性" sortable></el-table-column>
            <el-table-column prop="IsCanceled"  label="注销标志" sortable></el-table-column>
            <el-table-column prop="Transactor"  label="阅办人" sortable></el-table-column>
            <el-table-column label="下载" fixed="right">
              <template slot-scope="scope">
                <el-button type="text" class="el-icon-download" @click="downBtn(scope.row)" size="mini">下载</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page="currentPage"
            :page-sizes="pagerange"  class="mt"  :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"  :total="totalnum"  ></el-pagination>
        </div>
    </div>
    <!--dialog-->
    <el-dialog :title="titleName" :visible.sync="dialogVisible">
      <span>
        <el-form ref="formData" :model="formData" width="50%" style="margin-left:2%;" :rule="formRule" label-width="120px">
        <el-form-item label="来文单位：" prop="txtFromOrg">
          <el-input v-model="formData.txtFromOrg" style="width: 220px;" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="来文时间：" prop="txtFromDate">
          <el-date-picker :disabled="true" type="datetime" v-model="formData.txtFromDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item label="事由：" prop="txtReason">
          <el-input v-model="formData.txtReason" style="width: 220px;" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="来文字号：" prop="txtFileWordNo">
          <el-input v-model="formData.txtFileWordNo" style="width: 220px;" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="标题：" prop="txtSubject">
          <el-input v-model="formData.txtSubject" style="width: 220px;" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="附加内容：">
          已有附件
        </el-form-item>
        <el-form-item label="时效性：">
          <el-input v-model="formData.txtExpiryHours" style="width: 100px;" :disabled="true"></el-input>
          <el-select v-model="formData.TimeType" style="width: 100px;" :disabled="true">
            <el-option label="小时" value="hours"></el-option>
            <el-option label="天" value="days"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="阅办人：" prop="txtTransactor">
          <el-select v-model="formData.txtTransactor" placeholder="请选择复查人" :disabled="true">
            <el-option v-for="(t,i) in usedList" :label="t.name" :key="i" :value="t.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理意见：" prop="txtHandleSuggestions">
          <el-input v-model="formData.txtHandleSuggestions" :disabled="true" style="width: 220px;" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="审批意见：" prop="txbAduitResult">
          <el-select v-model="formData.txbAduitResult">
            <el-option label="同意" value="0"></el-option>
            <el-option label="不同意" value="2"></el-option>
          </el-select>
          <el-checkbox v-model="formData.cbxIsFinal" label="最终审批环节" ></el-checkbox>
        </el-form-item>
        <el-form-item label="下一审批岗位：" prop="ddlNextRoleID">
          <el-select v-model="formData.ddlNextRoleID" placeholder="请选择">
            <el-option v-for="(t,i) in auditList" :label="t" :key="i" :value="i"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="commonType != 3" @click="submitData('formData')" :disabled="formData.isShow">确 定</el-button>
        <el-button @click="cancelBtn('formData')">取 消</el-button>
      </span>
    </el-dialog>
    <!--el-dialog-->
    <el-dialog :visible.sync="dialogVisible1">
      <span>
        <img :src="imgurl" style="width:360px;"/>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!--el-dialog-->
  </div>
</template>
<script>
import {getFileAduitList,getFileReleaseList,getFileQueryList,aduitFileMess,releaseFileMess} from '@/ajax';
import common from '@/utils/common.js';
import config from './Manage.js';
export default {
    data(){
        return {
          searchdata:{
            txtFromOrg:'',txtReason:'',txtFileWordNo:'',txtSubject:''
          },
          totalnum: 0,
          currentPage: 0,
          pagerange: [2, 10, 20, 50, 100],
          pagesize: 10,
          tableData:[],
          dialogVisible:false,
          formData:{txtFromOrg:'',txtFromDate:'',txtReason:'',txtFileWordNo:'','isShow':false,
                    txtSubject:'',txtExpiryHours:'',TimeType:'hours',cbxIsFinal:'',FileID:'',
                    txtTransactor:'',txtHandleSuggestions:'',ddlNextRoleID:'',txbAduitResult:''},
          formRule:{
            txbAduitResult:{required:true,message:'请选择审批意见',trigger:'blur'},
            ddlNextRoleID:{required:true,message:'请选择下一审批人',trigger:'blur'},
          },
          selection:{},
          dialogVisible1:false,
          imgurl:'',
          common:common,
          config:config,
          auditList:config.aduitList,
          usedList:[{'id':'123','name':'lily'}],
          titleName:'',
          isConfirm:false,
          method:''
        }
    },
    props:['commonType'],
    mounted(){
      this.getFileReadList();
      if(this.commonType == 1){
        this.titleName = '文件阅办单审核'
      }else if(this.commonType == 2){
        this.titleName = '文件阅办单发布'
      }else if(this.commonType == 3){
        this.titleName = '文件阅办单审阅'
      }
    },
    inject:['reload'],
    methods:{
      searchBtn(){
        this.getFileReadList();
      },
      //TODO 是否有查看详情的接口
      handleSelectionChange(val){
        if(val){
          this.selection = val
        }
      },
      getFileReadList(){
        this.searchdata['page'] = this.pagesize;
        this.searchdata['rows'] = this.currentPage;
        this.tableData = config.fileList;
        this.totalnum = this.tableData.length;
     /*   if(this.commonType == 1){
          this.method = getFileAduitList(this.searchdata)
        }else if(this.commonType == 2){
          this.method = getFileReleaseList(this.searchdata)
        }else if(this.commonType == 3){
          this.method = getFileQueryList(this.searchdata)
        }
        this.method.then((res) => {
          if (res.data.code == '00000') {
            if(res.data.data.length > 0){
              this.tableData = res.data.data;
              this.totalnum = this.tableData.length;
            }else{
              this.tableData = [];
              this.totalnum = 0;
            }
          } else {
            this.$message(res.data.message);
          }
          }).catch(()=>{
            this.tableData = [];
            this.totalnum = 0;
            this.$message('服务器正忙，获取'+this.titleName+'列表失败');
          }) */
      },
      //分页
      handleSizeChange(val){
          this.pagesize = val;
          this.getFileReadList();
      },
      handleCurrentChange(val){
          this.currentPage = val;
          this.getFileReadList();
      },
      aduitBtn(){
        if(!this.selection[0]){
          this.$message('请选择一条数据')
        }else{
          // txtFromOrg:'',txtFromDate:'',txtReason:'',txtFileWordNo:'',
           // txtSubject:'',txtExpiryHours:'',TimeType:'hours',cbxIsFinal:'',
            //txtTransactor:'',txtHandleSuggestions:'',ddlNextRoleID:'',txbAduitResult:''
          this.formData = this.selection[0]
          this.formData.txtFromOrg= this.selection[0].FromOrg
          this.formData.txtFromDate= this.selection[0].FromDate
          this.formData.txtReason= this.selection[0].Reason
          this.formData.txtExpiryHours= this.selection[0].ExpiryHours
          this.formData.txtTransactor = this.selection[0].Transactor
          this.formData.txtSubject = this.selection[0].Subject
          this.formData.txtFileWordNo =  this.selection[0].FileWordNo
          this.dialogVisible = true;
        }
      },
      cancelBtn(form){
        this.$refs[form].clearValidate();
        this.$refs[form].resetFields();
        this.dialogVisible=false;
      },
      //进行添加（通过type区分应用确定，应用1确定2）
      submitData(form){
        this.$refs[form].validate((valid) => {
          if(valid){
            let method = '';
            if(this.commonType == 1){
              method = aduitFileMess(this.formData)
            }else if(this.commonType == 2){
              method = releaseFileMess(this.formData)
            }
            method.then((res) => {
                if (res.data.code == '00000') {
                  this.formData.isShow = true
                  this.reload()
                } else {
                  this.$message(res.data.message);
                }
              }).catch(()=>{
                this.$message('服务器正忙，操作失败');
            })
          }else{
            return false
          }
        })
      },
      downBtn(row){
        //根据文件类型 图片则弹窗框展示，文件则下载？
        if(row.fileUpload){
          let filetype = row.fileUpload.split('.');
          let imgType =['jpg','jpeg','png','gif']
          let flag = filetype[filetype.length - 1]
          if(common.checkStringInArr(flag,imgType)){
            this.imgurl = row.fileUpload
            this.dialogVisible1 = true
          }else{
            window.location.href = row.fileUpload;
            //common.exportExcel(row.fileUpload,'扫描文件',"application/vnd.ms-excel",flag)
          }
        }else{
          this.$message('没有要下载的扫描件')
        }
      }

    },
    watch:{

    }
}
</script>
<style lang="scss">
.public-common{
    .public-title{line-height: 30px;background-color: #deecfd;}
    .inline-btn{display: inline-flex;margin: 20px;
      label{width:100px;line-height: 32px;margin-left:10px;text-align: right;}
      .el-input{width: 170px;}
      .el-button{margin-left:10px;}
    }
    .el-form-item .el-input,.el-select,.el-date-picker{width: 200px !important;}
    .left{display: inline-block;;width:64%;float: left;}
    .right{display: inline-block;;width:35%;float: left;}
    .el-form .inline-btn{margin:unset;}
    .footer{
      width: 100%;
      display: inline-flex;
      margin-left: 72%;
    }
}
</style>
